package com.ase.leetcode;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @author gyhstart
 * @create 2021/3/11 - 11:40
 **/
public class test2 {
    public static void main(String[] args) {
        stream();
    }

    public static void stream() {
//        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
//        List<String> filtered = strings.stream()
//                .filter(string -> !string.isEmpty())
//                .collect(Collectors.toList());
//        System.out.println("filtered = " + filtered);

//        Random random = new Random();
//        random.ints().limit(2).forEach(System.out::println);

        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        // 获取对应的平方数
        List<Integer> squaresList = numbers
                .stream()
                .map( i -> i*i)
                .distinct()
                .collect(Collectors.toList());
        System.out.println("squaresList = " + squaresList);

        List<String>strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        // 获取空字符串的数量
        long count = strings.stream()
                .filter(string -> string.isEmpty()).count();
        System.out.println("count = " + count);

        Random random = new Random();
        //使用 sorted 方法对输出的 10 个随机数进行排序
        random.ints().limit(10).sorted().forEach(System.out::println);

        List<String>strings2 = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        List<String> filtered = strings2.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());

        System.out.println("筛选列表: " + filtered);
        String mergedString = strings2.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining("-"));
        System.out.println("合并字符串: " + mergedString);
    }
}
